import { defineStore } from "pinia";
import { ref, reactive, computed, watch } from 'vue';
//暴露一个todoList小仓库->组合式API写法
const useTodoStore = defineStore('todoList', () => {
    //state
    const a = ref(1);
    const b = ref(2);
    const arr = ref([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
    //actions
    const add = () => {
        a.value++;
    }
    //getters
    const total = computed(() => {
        return arr.value.reduce((prev: any, next: any) => {
            return prev += next;
        }, 0)
    })
    
    //监听属性
    watch(a, () => {
        console.log(123);
    });

    //回调返回对象的属性与方法可以提供给组件使用
    return {
        a,
        b,
        arr
        ,
        add,
        total
    }
});
export default useTodoStore;